import {hasAuth} from '@/plugins/permission'

/**
 * 按钮权限
 */
export function hasPerm(app) {
    app.directive('hasPerm', {
        mounted(el, binding) {
            // DOM绑定需要的按钮权限标识
            const {value: requiredPerms} = binding
            if (requiredPerms) {
                if (!hasAuth(requiredPerms)) {
                    el.parentNode && el.parentNode.removeChild(el)
                }
            } else {
                throw new Error(
                  'need perms! Like v-has-perm="[\'sys:user:add\',\'sys:user:edit\']"'
                )
            }
        }
    })
}
